//
//  HWVipGiftBagGameHeader.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/10.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWVipGiftBagGameHeader: UIView {

    var gameImageView:UIImageView!
    var gameNameLabel:UILabel!
    
//    class func headerOrFooterWithTableView(tableView:UITableView) -> (HWVipGiftBagGameHeader) {
//        let reUse:String = "HWVipGiftBagGameHeader"
//
//        var headerOrFooter = tableView.dequeueReusableHeaderFooterView(withIdentifier: reUse)
//
//        if headerOrFooter == nil {
//            headerOrFooter = HWVipGiftBagGameHeader.init(reuseIdentifier: reUse)
//        }
//
//        return headerOrFooter as! HWVipGiftBagGameHeader
//    }
//
    var model:HWVipGiftBagModel? {
        didSet {
            gameImageView.sd_setImage(with: URL(string: model?.icon ?? ""), completed: nil)
            gameNameLabel.text = model?.gname
        }
    }
    var couponsModel:HWCouponsModel? {
        didSet {
            gameImageView.sd_setImage(with: URL(string: couponsModel?.icon ?? ""), completed: nil)
            gameNameLabel.text = couponsModel?.gname
        }
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    override init(reuseIdentifier: String?) {
//        super.init(reuseIdentifier: reuseIdentifier)
//        initUI()
//        initFrame()
//    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUI()
        initFrame()
    }
    func initUI() -> Void {
        
//        contentView.backgroundColor = .white
//        backgroundView?.backgroundColor = .white
        backgroundColor = .white
        gameImageView = UIImageView()
        gameImageView.backgroundColor = .clear
        gameImageView.layer.cornerRadius = 8
        gameImageView.layer.masksToBounds = true
        addSubview(gameImageView)
        
        gameNameLabel = HWLabel.createBoldLabel(title: "-", color: "#333333", font: 12)
        addSubview(gameNameLabel)
        
        
    }
    
    func initFrame() -> Void {
        gameImageView.snp.makeConstraints { make in
            make.left.equalTo(15*widthScale)
            make.top.equalTo(9*widthScale)
            make.width.height.equalTo(40*widthScale)
        }
        
        gameNameLabel.snp.makeConstraints { make in
            make.left.equalTo(gameImageView.snp.right).offset(4*widthScale)
            make.centerY.equalTo(gameImageView)
        }
    }

}
